package com.lancoo.ccas52.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.lancoo.ccas52.aspect.LogAnnotation;
import com.lancoo.ccas52.entity.CourseApply;
import com.lancoo.ccas52.entity.SegmentApply;
import com.lancoo.ccas52.pojo.vo.*;
import com.lancoo.ccas52.service.CourseService;
import com.lancoo.ccas52.util.ResponseObject;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @ClassName CourseSegmentController
 * @Description TODO
 * @Author quin
 * @Date 2023/1/5 8:47
 */
@Api(tags = "课程环节相关接口控制器")
@RestController
@RequestMapping("/api/v5.2.1/pc/courseSegment")
public class CourseSegmentController {

    @Resource
    private CourseService courseService;

    @ApiOperation("获取课程/环节类别")
    @GetMapping(value = "/getType")
    public ResponseObject<List<CourseTypeDto>> getTeacherPlan(@ApiParam(value = "任务流程id", required = true) @RequestHeader Integer taskId,
                                                              @ApiParam(value = "1课程 2环节", required = true) @RequestParam Integer flag) {
        return ResponseObject.ofSuccess(courseService.getCourseTypeByTaskId(taskId, flag));
    }

    @ApiOperation("获取课程列表-关联审核信息")
    @GetMapping(value = "/course/getCourseAndApply")
    public ResponseObject<ApplyStatistics<CourseApplyDto>> getCourseAndApply(@ApiParam(value = "任务流程id", required = true) @RequestHeader Integer taskId,
                                                                             @ApiParam(value = "申请状态 1正常开课 2审核中 3已通过 4已驳回 5已处理", required = false) @RequestParam(required = false) Integer applyStatus,
                                                                             @ApiParam(value = "课程类别id 传null全部", required = false) @RequestParam(required = false) String courseTypeId,
                                                                             @ApiParam(value = "课程性质 0全部 1必修  2选修", required = false) @RequestParam(required = false) Integer courseNature,
                                                                             @ApiParam(value = "专业性质，1:公共课，2:专业课", required = false) @RequestParam(required = false) Integer majorProp,
                                                                             @ApiParam(value = "学院id ", required = false) @RequestParam(required = false) String collegeId,
                                                                             @ApiParam(value = "课程名模糊查询", required = false) @RequestParam(required = false) String keyWord,
                                                                             @ApiParam(value = "页码", required = true) @RequestParam Integer currentPage,
                                                                             @ApiParam(value = "页容", required = true) @RequestParam Integer pageSize) {
        Page<CourseApplyDto> page = new Page<>(currentPage, pageSize);
        return ResponseObject.ofSuccess(courseService.getCourseDtoByConditions(taskId, page, applyStatus, courseTypeId, courseNature, majorProp, collegeId, keyWord));
    }

    @ApiOperation("获取环节列表-关联审核信息")
    @GetMapping(value = "/segment/getSegmentAndApply")
    public ResponseObject<ApplyStatistics<SegmentDto>> getSegmentAndApply(@ApiParam(value = "任务流程id", required = true) @RequestHeader Integer taskId,
                                                                          @ApiParam(value = "申请状态 1正常开课 2审核中 3已通过 4已驳回 5已处理", required = false) @RequestParam(required = false) Integer applyStatus,
                                                                          @ApiParam(value = "课程类别id 传null全部", required = false) @RequestParam(required = false) String segmentTypeId,
                                                                          @ApiParam(value = "学院id ", required = false) @RequestParam(required = false) String collegeId,
                                                                          @ApiParam(value = "环节名模糊查询", required = false) @RequestParam(required = false) String keyWord,
                                                                          @ApiParam(value = "页码", required = true) @RequestParam Integer currentPage,
                                                                          @ApiParam(value = "页容", required = true) @RequestParam Integer pageSize) {
        Page<SegmentDto> page = new Page<>(currentPage, pageSize);
        return ResponseObject.ofSuccess(courseService.getSegmentDtoByConditions(taskId, page, applyStatus, segmentTypeId, collegeId, keyWord));
    }

    @ApiOperation("课程-申请开课变更")
    @PostMapping(value = "/course/dealCourseApply")
    @LogAnnotation(operationType = "5", operationContent = "课程-申请开课变更")
    public ResponseObject<CourseApply> dealCourseApply(@ApiParam(value = "任务流程id", required = true) @RequestHeader Integer taskId,
                                                       @ApiParam(value = "用户id", required = true) @RequestHeader String userId,
                                                       @ApiParam(value = "用户名字", required = true) @RequestHeader String userName,
                                                       @ApiParam(value = "申请实体类", required = true) @Validated @RequestBody CourseApplyInput courseApplyInput) {

        return ResponseObject.ofSuccess(courseService.dealCourseApply(taskId, userId, userName, courseApplyInput));
    }

    @ApiOperation("环节-申请开课变更")
    @PostMapping(value = "/segment/dealSegmentApply")
    @LogAnnotation(operationType = "5", operationContent = "环节-申请开课变更")
    public ResponseObject<SegmentApply> dealSegmentApply(@ApiParam(value = "任务流程id", required = true) @RequestHeader Integer taskId,
                                                         @ApiParam(value = "用户id", required = true) @RequestHeader String userId,
                                                         @ApiParam(value = "用户名字", required = true) @RequestHeader String userName,
                                                         @ApiParam(value = "申请实体类", required = true) @Validated @RequestBody SegmentApplyInput segmentApplyInput) {
        return ResponseObject.ofSuccess(courseService.dealSegmentApply(taskId, userId, userName, segmentApplyInput));
    }

    @ApiOperation("获取课程列表（增开课程）")
    @GetMapping(value = "/course/getCourseList")
    public ResponseObject<List<AddCourseSegment>> getNotEnableCourseList(@ApiParam(value = "任务流程id", required = true) @RequestHeader Integer taskId,
                                                                         @ApiParam(value = "课程类别id 传null全部", required = false) @RequestParam(required = false) String courseTypeId,
                                                                         @ApiParam(value = "课程性质 1必修  2选修", required = false) @RequestParam(required = false) Integer courseNature,
                                                                         @ApiParam(value = "专业性质，1:公共课，2:专业课", required = false) @RequestParam(required = false) Integer majorProp,
                                                                         @ApiParam(value = "学院id ", required = false) @RequestParam(required = false) String collegeId,
                                                                         @ApiParam(value = "课程名模糊查询", required = false) @RequestParam(required = false) String keyWord) {
        return ResponseObject.ofSuccess(courseService.getNotEnableCourseList(taskId, courseTypeId, courseNature, majorProp, collegeId, keyWord));
    }

    @ApiOperation("获取环节列表（增开课程）")
    @GetMapping(value = "/segment/getSegmentList")
    public ResponseObject<List<AddCourseSegment>> getNotEnableCourseList(@ApiParam(value = "任务流程id", required = true) @RequestHeader Integer taskId,
                                                                         @ApiParam(value = "学院id ", required = false) @RequestParam(required = false) String collegeId,
                                                                         @ApiParam(value = "课程名模糊查询", required = false) @RequestParam(required = false) String keyWord) {
        return ResponseObject.ofSuccess(courseService.getNotEnableSegmentList(taskId, collegeId, keyWord));
    }

    @ApiOperation("开课变更审核")
    @PutMapping(value = "/examineApply")
    @LogAnnotation(operationType = "6", operationContent = "开课变更审核")
    public ResponseObject<Boolean> examineApply(@ApiParam(value = "1课程 2环节", required = true) @RequestParam Integer flag,
                                                @ApiParam(value = "1：通过，2：驳回", required = true) @RequestParam Integer examine,
                                                @ApiParam(value = "申请id", required = true) @RequestParam Integer applyId,
                                                @ApiParam(value = "审核意见", required = false) @RequestParam(required = false) String reviewComment) {
        return ResponseObject.ofSuccess(courseService.examineApply(flag, examine, applyId, reviewComment));
    }

    @ApiOperation("统计-发布开课计划")
    @GetMapping(value = "/publishStatistics")
    public ResponseObject<PublishStatistics> applyStatistics(@ApiParam(value = "任务流程id", required = true) @RequestHeader Integer taskId) {
        return ResponseObject.ofSuccess(courseService.getPublishStatistics(taskId));
    }

    @ApiOperation("校验开课计划数据")
    @PutMapping(value = "/checkPublishPlan")
    public ResponseObject<Boolean> checkPublishPlan(@ApiParam(value = "任务流程id", required = true) @RequestHeader Integer taskId) {
        return ResponseObject.ofSuccess(courseService.checkPublishPlan(taskId));
    }

    @ApiOperation("发布开课计划")
    @PutMapping(value = "/publishPlan")
    @LogAnnotation(operationType = "8", operationContent = "发布开课计划")
    public ResponseObject<Boolean> publishPlan(@ApiParam(value = "任务流程id", required = true) @RequestHeader Integer taskId) {
        return ResponseObject.ofSuccess(courseService.publishPlan(taskId));
    }


}
